package com.effect
{
	import mx.effects.Move;
	import mx.effects.Parallel;
	import mx.effects.Resize;
	import mx.effects.Rotate;
	import mx.effects.Sequence;
	import mx.events.EffectEvent;
	import mx.managers.PopUpManager;
	
	public class TitleWindowEffect
	{
		public var angle : int = 0;
		public static var instence : TitleWindowEffect = null;
		
		private const min_width:int = 350; 
        private const min_height:int = 200; 
		
		public static function getInstence() : TitleWindowEffect
		{
			if(instence == null) {
				instence = new TitleWindowEffect();
			}
			return instence;
		}
		/**
		 * 弹出Title的效果
		 */ 
		public function popupTitleWindow(tw : *,xFrom : Number,yFrom : Number,xTo : Number = 410,
												yTo : Number = 120,widthFrom : Number = 300,widthTo : Number = 650,heightFrom : Number = 200,heightTo : Number = 550) : void {
			var parelel : Parallel = new Parallel();
			
			var resize : Resize = new Resize();
			resize.target = tw;
			resize.duration = 2000;	
			resize.widthFrom = widthFrom;	
			resize.widthTo = widthTo;	
			resize.heightFrom = heightFrom;			
			resize.heightTo = heightTo;				
			parelel.addChild(resize);
			
			var move : Move = new Move();
			move.target = tw;				
			move.duration = 2000;   
			move.xFrom = xFrom;
			move.xTo   = xTo;
			move.yFrom = yFrom;				
			move.yTo   = yTo;
			parelel.addChild(move);
			
			var rotate : Rotate = new Rotate();				
			rotate.target = tw;
			angle += 90;
			rotate.duration = 1000;       	
			parelel.addChild(rotate);
			
			parelel.play();
		}
		/**
		 * 关闭Title的效果
		 */ 
		public function closePopupTitleWindow(tw : *,xTo : Number = 1050,yTo : Number = 190,widthTo : Number = 0,heightTo : Number = 0) : void {
			var parallel : Parallel = new Parallel();
			
			var resize : Resize = new Resize();
			resize.target = tw;
			resize.duration = 1000;
			resize.widthTo = widthTo;				
			resize.heightTo = heightTo;				
			parallel.addChild(resize);                	
          	
          	var move : Move = new Move();
			move.target = tw;				
			move.duration = 1000;   
			move.xTo   = xTo;
			move.yTo   = yTo;
			parallel.addChild(move);
			
			var rotate : Rotate = new Rotate();								
          	angle -= 90;
          	rotate.duration = 1000;              	             
          	rotate.target = tw;
          	parallel.addChild(rotate);
          	
          	parallel.play()
          	parallel.addEventListener(EffectEvent.EFFECT_END,function(event : EffectEvent) {closeTitleWindow(event,tw)});
		}
		private function closeTitleWindow(event : EffectEvent,tw : *) : void {
			PopUpManager.removePopUp(tw);
		}
		public function popupTitleWindowResize(tw : *,xFrom : Number = 1050,yFrom : Number = 240,xTo : Number = 510,
												yTo : Number = 250,widthFrom : Number = 0,widthTo : Number = 500,heightFrom : Number = 0,heightTo : Number = 300) : void {
			var parallel:Parallel = new Parallel(); 
			var mymove : Move = new Move();
			mymove.target     = tw;
			mymove.duration   = 400;
			mymove.xFrom      = xFrom;
			mymove.xTo        = xTo;
			mymove.yFrom      = yFrom;
			mymove.yTo        = yTo;
			parallel.addChild(mymove)
			
			var resize : Resize = new Resize(); 
			resize.target       = tw;
			resize.duration     = 800;
			resize.widthFrom    = widthFrom;
			resize.widthTo      = widthTo;
			resize.heightFrom   = heightFrom;
			resize.heightTo     = heightTo;
			parallel.addChild(resize)
			
			parallel.play();
		}
		public function closePopupTitleWindowResize(tw : *,xTo : Number = 1050,yTo : Number = 240,widthTo : Number = 0,heightTo : Number = 0) : void {
			var parallel:Parallel = new Parallel(); 
			var mymove : Move = new Move();
			mymove.target     = tw;
			mymove.duration   = 1000;
			mymove.xTo        = xTo;
			mymove.yTo        = yTo;
			parallel.addChild(mymove)
			
			var resize : Resize = new Resize(); 
			resize.target       = tw;
			resize.duration     = 1000;
			resize.widthTo      = widthTo;
			resize.heightTo     = heightTo;
			parallel.addChild(resize)
			
			parallel.play();
			parallel.addEventListener(EffectEvent.EFFECT_END,function(event : EffectEvent) {closeTitleWindow(event,tw)});
		}
	}
}